package com.aysafety.iotdataplatformserver.configurer;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
public class SaveDataThreadPoolConfigurer {
    @Autowired
    SaveDataThreadPoolConfig saveDataThreadPoolConfig;

    @Bean
    public Executor ETLAsyncPool() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(saveDataThreadPoolConfig.getCorePoolSize());
        executor.setMaxPoolSize(saveDataThreadPoolConfig.getMaxPoolSize());
        executor.setQueueCapacity(saveDataThreadPoolConfig.getQueueCapacity());
        executor.setKeepAliveSeconds(saveDataThreadPoolConfig.getKeepAliveSeconds());
        executor.setThreadNamePrefix("SaveDataThreadPool-");
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.initialize();
        return executor;
    }


}
